<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>销售人员：</label>
                                <select name="salesPersonNum" class="form-control">
                                    <option selected hidden value="">-请选择销售人员-</option>
                                    <option th:each="dict : ${sysUsers}" th:text="${dict.userName}"
                                            th:value="${dict.userName}"></option>
                                </select>
                        </li>
                        <li>
                            <label>房间号：</label>
                            <input type="text" name="roomNum"/>
                        </li>
                        <li>
                            <label>是否交付：</label>
                            <select name="flag" th:with="type=${@dict.getType('sys_sales_flag')}">
                                <option selected hidden value="">-请选择是否交付-</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>出售日期：</label>
                            <input type="text" class="time-input" placeholder="请选择出售日期" name="salesDate"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:sales:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:sales:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:sales:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:sales:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:sales:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:sales:remove')}]];
    var date = [[${@dict.getType('sys_room_type')}]];
    var prefix = ctx + "system/sales";
    var prefix1 = ctx + "system/contract";
    $(function() {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName:"销售管理",
            columns: [{
                checkbox: true
            },
                {
                    field: 'salesId',
                    title: '唯一id',
                    visible: false
                },
                {
                    field: 'salesNum',
                    title: '售房编号'
                },
                {
                    field: 'salesPersonNum',
                    title: '销售人员'
                },
                {
                    field: 'roomNum',
                    title: '房间号'
                },
                {
                    field: 'salesPeice',
                    title: '价格'
                },
                {
                    field: 'salesApartment',
                    title: '房型',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(date, value);
                    }
                },
                {
                    field: 'salesAdvanceCharge',
                    title: '预付款'
                },
                {
                    field: 'salesTransactionPrice',
                    title: '成交价'
                },
                {
                    field: 'flag',
                    title: '是否交付',
                    formatter: function (value, row, index) {
                        return statusTools(row);
                    }
                },
                {
                    field: 'purchaseName',
                    title: '购房人'
                },
                {
                    field: 'salesDate',
                    title: '出售日期'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.salesId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.salesId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    /* 状态显示 */
    function statusTools(row) {
        if (row.flag == 1) {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.salesId + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.salesId + '\')"></i> ';
        }
    }

    /* 停用 */
    function disable(salesId) {
        $.modal.confirm("取消交付？", function () {
            $.operate.post(prefix + "/edit", {"salesId": salesId, "flag": 1});
        })
    }

    /* 启用 */
    function enable(salesId) {
        $.modal.confirm("确认交付？", function () {
            $.operate.post(prefix + "/edit", {"salesId": salesId, "flag": 0});
        })
    }

    function openShowPage(salesId){
        if (salesId == undefined || salesId == null ||salesId == ''){
            return;
        }
        $.modal.open("查看合同信息", prefix1 + "/salesShow/" + salesId);
    }
</script>
</body>
</html>